import json

from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from rest_framework.views import APIView
from rest_framework.authentication import BasicAuthentication


# Create your views here.

# 俩种方法都可以
# def order(request):
#     if request.method == 'GET':
#         return HttpResponse('获取订单')
#     elif request.method == 'POST':
#         return HttpResponse('创建订单')
#     elif request.method == 'PUT':
#         return HttpResponse('更新订单')
#     elif request.method == 'DELETE':
#         return HttpResponse('删除订单')


class OrderView(View):
    def get(self, request, *args, **kwargs):
        res = {
            'code': 1000,
            'msg': 'ok'
        }
        return HttpResponse(json.dumps(res), status=200)

    def post(self, request, *args, **kwargs):
        return HttpResponse('创建订单')

    def put(self, request, *args, **kwargs):
        return HttpResponse('更新订单')

    def delete(self, request, *args, **kwargs):
        return HttpResponse('删除订单')


class DogView(APIView):
    def get(self, request, *args, **kwargs):
        res = {
            'code': 1000,
            'msg': 'ok'
        }
        return HttpResponse(json.dumps(res), status=200)